import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provider/provider.dart';
import '../../provider/details_info.dart';
import '../../model/goodDetail.dart';

class DetailsPageTop extends StatelessWidget {
  const DetailsPageTop({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Consumer<DetaiInfoProvider>(
        builder: (context, DetaiInfoProvider detailsInfoProvider, child) {
          GoodInfo goodInfo = detailsInfoProvider.goodsInfo.data.goodInfo;
          return Column(
            children: <Widget>[
              _goodsImage(goodInfo.image1),
              _goodsName(goodInfo.goodsName),
              _goodsNum(goodInfo.goodsSerialNumber),
              _goodsPrice(goodInfo.presentPrice, goodInfo.oriPrice)
            ],
          );
        },
      ),
    );
  }

  // 商品图片
  Widget _goodsImage(String url) {
    return Image.network(
      url,
      width: ScreenUtil().setWidth(740),
    );
  }

  // 商品名称
  Widget _goodsName(String name) {
    return Container(
      width: ScreenUtil().setWidth(730),
      padding: EdgeInsets.only(left: 15.0, top: 10.0),
      child: Text(
        name,
        style: TextStyle(
          fontSize: ScreenUtil().setSp(30)
        ),
      ),
    );
  }

  // 编号
  Widget _goodsNum(String serialNum) {
    return Container(
      width: ScreenUtil().setWidth(730),
      padding: EdgeInsets.only(left: 15.0),
      margin: EdgeInsets.only(top: 10.0),
      child: Text(
        '编号：$serialNum',
        style: TextStyle(
          color: Colors.black26 
        ),
      ),
    );
  }

  // 商品价格方法
  Widget _goodsPrice(double presentPrice, double oriPrice) {
    return Container(
      width: ScreenUtil().setWidth(730),
      padding: EdgeInsets.only(left: 15.0),
      margin: EdgeInsets.only(top: 8.0),
      child: Row(
        children: <Widget>[
          Text(
            '￥$presentPrice',
            style: TextStyle(
              fontSize: ScreenUtil().setSp(40),
              color: Colors.pinkAccent
            ),
          ),
          Text(
            ' 市场价:￥$oriPrice',
            style: TextStyle(
              color: Colors.black26,
              decoration: TextDecoration.lineThrough,
            ),
          ),
        ],
      ),
    );
  }
}